home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / include / sun3.md / mon / RCS / keyboard.h,v < prev    next >
Encoding:
Text File  |  1989-07-14  |  13.2 KB  |  400 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     89.07.14.09.23.27;  author rab;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     89.07.14.09.20.52;  author rab;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @*** empty log message ***
  27. @
  28. text
  29. @/*      @@(#)keyboard.h 1.1 86/10/07 SMI; from UCB X.X XX/XX/XX       */
  30.  
  31. /*
  32.  * Copyright (c) 1986 by Sun Microsystems, Inc.
  33.  */
  34.  
  35. /*
  36.  * Header file for Sun Microsystems keyboard routines
  37.  *
  38.  * The keyboard is a standard Micro Switch, or otherwise, keyboard,
  39.  * with an 8048/8748 on the board.  This has been modified to produce
  40.  * up/down keycodes.
  41.  *
  42.  * On Sun-1 keyboards these keycodes are output on 8 parallel output lines.
  43.  * Each keycode is held stable on these lines for a minimum of 2.5 ms in
  44.  * order that the main processor can read it during its refresh
  45.  * routine, which executes every 2 ms or so.
  46.  *
  47.  * On Sun-2 keyboards, the keycodes are transmitted on a serial line
  48.  * at 1200 baud.
  49.  *
  50.  * When no physical keys are depressed, the keyboard transmits a keycode of
  51.  * "IDLE" (7F hex), to indicate that.  Thus, when the last key is released,
  52.  * a keycode for its release is sent, then an IDLE.  Note that virtual
  53.  * keys on the VT100 kbd (eg CAPS LOCK) can be down when the IDLE code
  54.  * is received.
  55.  *
  56.  * The Sun-1 VT100 keyboard will follow each of its IDLE's with a
  57.  * keyboard id code, identifying the key layout or other factors
  58.  * which host programs might want to automatically determine.
  59.  * The support for this feature is marked with "#ifdef KBDID".
  60.  * The only good it currently does us is to tell us the state of
  61.  * the "caps lock" LED/virtual key when we have been reset.
  62.  *
  63.  * The low 4 bits of the id byte contain the keyboard ID (currently
  64.  * 1 for VT100 keyboard); the high order bit is set (to make sure
  65.  * there's a transition between the IDLE (7F) and the identification
  66.  * byte); the -XXX---- bits contain state information about the keyboard.
  67.  * These bits are allocated from opposite ends in case we need to shift
  68.  * the boundary.  The only state bit currently defined is 0x40, which is
  69.  * the current state of the CAPS LOCK LED.
  70.  *
  71.  * The Sun-2 keyboard also transmits two other "special" keycodes:
  72.  *
  73.  *    RESETKEY    upon power-up, when no errors are detected,
  74.  *            this code is sent and followed by the keyboard id,
  75.  *            a byte containing 0x02.
  76.  *
  77.  *    ERRORKEY    upon power-up, when errors are detected,
  78.  *            this code is sent and followed by a "cause" byte
  79.  *            giving more details.  There is only one cause byte
  80.  *            defined so far -- checksum error on PROM.
  81.  *
  82.  * Due to table size limits, the configuration file for the
  83.  * ROM monitor must specify what keyboard it will support, by using:
  84.  *     options KEYBKL or KEYBVT or KEYBS2
  85.  *
  86.  */
  87.  
  88. #ifndef IDLEKEY
  89.  
  90. /*
  91.  * Various special characters that might show up on the port
  92.  */
  93.  
  94. /* Both of these are followed by 1 byte of parameters. */
  95.  
  96. #define    RESETKEY    0xFF        /* Keyboard was just reset */
  97. #define    ERRORKEY    0x7E        /* Keyboard detected an error */
  98. #define    IDLEKEY        0x7F        /* Keyboard is idle; no keys down */
  99. #define    PRESSED        0x00        /* 0x80 bit off: key was pressed */
  100. #define    RELEASED    0x80        /* 0x80 bit on : key was released */
  101.  
  102. /*
  103.  * Keyboard-specific information
  104.  */
  105. #ifdef sun2
  106. #ifndef KEYBS2
  107. /*
  108.  * How to get the current keycode being presented by the 8048
  109.  *
  110.  * GETKEYPORT reads the raw port; GETKEY deglitches it.
  111.  */
  112.  
  113. #define GETKEYPORT      ( *(unsigned char*) PARALLEL_BASE)
  114.  
  115. #define GETKEY(key) \
  116.         while (GETKEYPORT != ((key)=GETKEYPORT));
  117.  
  118. #endif /* KEYBS2 */
  119. /*
  120.  * Various special characters that might show up on the port
  121.  */
  122.  
  123. #ifndef  KEYBS2
  124. #define NOTPRESENT      0xFF            /* Keyboard is not plugged in */
  125. #endif /* KEYBS2 */
  126.  
  127. #ifdef KEYBKL
  128. /* Klunker style keyboard wired-in information */
  129. #define KB_UNKNOWN      KB_MS_103SD32   /* Unknown keyboard assumed klunker */
  130. #define ABORTKEY1       1               /* First key of abort seq - ERASE EOF */#define ABORTKEY2       77              /* 2nd key of abort seq - "A" */
  131. #endif /* KEYBKL */
  132.  
  133. #ifdef KEYBVT
  134. /* VT100 style keyboard wired-in information */
  135. /* With KBDID, the value of KB_UNKNOWN must be different from a real kbd id */
  136. /* Furthermore, it must not have any "transient keyboard state" bits on,
  137.    since the keyboard is initialized with this state (eg CAPS LOCK) */
  138. #define KB_UNKNOWN      0x06            /* Random unlikely to be seen */
  139. #define ABORTKEY1       1               /* First key of abort seq - Setup */
  140. #define ABORTKEY2       59              /* 2nd key of abort seq - "A" */
  141. #endif /* KEYBVT */
  142. #endif /* sun2 */
  143. #if !defined(KEYBVT) && !defined(KEYBKL)
  144. /* Sun-2 keyboard wired-in information */
  145. #define    KB_UNKNOWN    0xDE        /* Random unlikely to be seen */
  146.                 /* Changed to 0xDE for enough room  to expand*/
  147. #define    ABORTKEY1    1        /* First key of abort seq - L1 */
  148. #define    ABORTKEY2    77        /* 2nd key of abort seq - "A" */
  149. #endif
  150. /*
  151.  * Keyboard ID codes...transmitted by the various keyboards
  152.  * after the IDLEKEY code.  See top of file for more details.
  153.  * N.B.: Only the low order 4 bits encode the keyboard id;
  154.  *  don't forget to mask off the high nibble.
  155.  * The value of KB_UNKNOWN above must not match any of these,
  156.  * if KBDID is set.
  157.  */
  158. #define    KB_MS_103SD32    0x00        /* Micro Switch 103SD32-2 */
  159. #define    KB_VT100    0x01        /* Keytronics VT100 compatible */
  160. #define    KB_SUN2        0x02        /* Sun-2 custom keyboard */
  161.  
  162. /*
  163.  * Commands to the Sun-2 keyboard.
  164.  */
  165. #define    KBD_CMD_RESET    0x01        /* Reset keyboard as if power-up */
  166. #define    KBD_CMD_BELL    0x02        /* Turn on the bell */
  167. #define    KBD_CMD_NOBELL    0x03        /* Turn off the bell */
  168. #define    KBD_CMD_LED1    0x04        /* Turn on LED 1 */
  169. #define    KBD_CMD_NOLED1    0x05        /* Turn off LED 1 */
  170. #define    KBD_CMD_LED2    0x06        /* Turn on LED 2 */
  171. #define    KBD_CMD_NOLED2    0x07        /* Turn off LED 2 */
  172.  
  173. /*
  174.  * Commands to the Sun-3 keyboard.
  175.  */
  176. #define KBD_CMD_CLICK   0x0A            /* Turn on keyboard click */
  177. #define KBD_CMD_NOCLICK 0x0B        /* Turn off keyboard click */
  178.  
  179. /*
  180.  * Software related definitions
  181.  */
  182. /*
  183.  * These are the states that the keyboard scanner can be in.
  184.  *
  185.  * It starts out in STARTUP state.
  186.  */
  187. #define    STARTUP        0        /* Waiting for kbd to show up */
  188. #define    NORMAL        1        /* The usual (ho, hum) */
  189. #define    ABORT1        2        /* Got KEYABORT1 */
  190. #define    IDLE1        3        /* Got IDLE */
  191. #define    IDLE2        4        /* Got id byte, IDLE probably follows */
  192. #define    STARTUP2    5        /* Got 1st byte of startup */
  193. #define    STARTUPERR    6        /* Got 1st byte of error startup */
  194.  
  195.  
  196. /*
  197.  * Translation options for getkey()
  198.  *
  199.  * These are how you can have your input translated.
  200.  */
  201. #define    TR_NONE        0
  202. #define    TR_ASCII    1
  203.  
  204. /*
  205.  * These bits can appear in the result of TR_NONE getkey()s.
  206.  */
  207. #define    STATEOF(key)    ((key) & 0x80)    /* 0 = key down, 0x80 = key up */
  208. #define    KEYOF(key)    ((key) & 0x7F)    /* The key number that moved */
  209. #define    NOKEY        (-1)        /* The argument was 0, and no key was
  210.                        depressed.  They were all elated. */
  211.  
  212. /*
  213.  * These bits can appear in the result of TR_ASCII getkey()s.
  214.  * (NOKEY can also appear if no keypress was queued up.)
  215.  */
  216. #define    METABIT        0        /* Meta key depressed with key */
  217. #define    METAMASK    0x000080
  218. #define    SYSTEMBIT    1        /* Upper left key was down w/key */
  219. #define    SYSTEMMASK    0x000100
  220. /* other "bucky" bits can be defined at will.  See "BUCKYBITS" below. */
  221.  
  222. /*
  223.  * This defines the bit positions used within "shiftmask" to
  224.  * indicate the "pressed" (1) or "released" (0) state of shift keys.
  225.  * Both the bit numbers, and the aggregate masks, are defined.
  226.  *
  227.  * The "UPMASK" is a minor kludge.  Since whether the key is going
  228.  * up or down determines the translation table (just as the shift
  229.  * keys' positions do), we OR it with "shiftmask" to get "tempmask",
  230.  * which is the mask which is actually used to determine the
  231.  * translation table to use.  Don't reassign 0x0080 for anything
  232.  * else, or we'll have to shift and such to squeeze in UPMASK,
  233.  * since it comes in from the hardware as 0x80.
  234.  */
  235. #define    CAPSLOCK    0        /* Caps Lock key */
  236. #define    CAPSMASK    0x0001
  237. #define    SHIFTLOCK    1        /* Shift Lock key */
  238. #define    LEFTSHIFT    2        /* Left-hand shift key */
  239. #define    RIGHTSHIFT    3        /* Right-hand shift key */
  240. #define    SHIFTMASK    0x000E
  241. #define    LEFTCTRL    4        /* Left-hand (or only) control key */
  242. #define    RIGHTCTRL    5        /* Right-hand control key */
  243. #define ALT        6        /* Alternate key */
  244. #define    CTRLMASK    0x0030
  245. /* unused...        0x0040 */
  246. #define    UPMASK    0x0080
  247. #define    CTLSMASK    0x0100      /* Set if ^S was last keyed of ^S, ^Q;
  248.                        determines which NOSCOLL sends. */
  249.  
  250. /*
  251.  * This defines the format of translation tables.
  252.  *
  253.  * A translation table is 128 bytes of "entries", which are bytes
  254.  * (unsigned chars).  The top 4 bits of each entry are decoded by
  255.  * a case statement in getkey.c.  If the entry is less than 0x80, it
  256.  * is sent out as an ASCII character (possibly with bucky bits
  257.  * OR-ed in).  "Special" entries are 0x80 or greater, and
  258.  * invoke more complicated actions.
  259.  */
  260. struct keymap {
  261.     unsigned char    keymap[128];    /* maps keycodes to actions */
  262. };
  263.  
  264. /*
  265.  * A keyboard is defined by its keymaps and what state it resets at idle.
  266.  *
  267.  * The masks k_idleshifts and k_idlebuckys are AND-ed with the current
  268.  * state of  shiftmask  and  buckybits  when a "keyboard idle" code
  269.  * is received.  This ensures that where we "think" the shift & bucky
  270.  * keys are, more accurately reflects where they really are, since the
  271.  * keyboard knows better than us.
  272.  */
  273. struct keyboard {
  274.     struct keymap    *k_normal;    /* Unshifted */
  275.     struct keymap    *k_shifted;    /* Shifted */
  276.     struct keymap    *k_caps;    /* Caps locked */
  277.     struct keymap    *k_control;    /* Controlled */
  278.     struct keymap    *k_up;        /* Key went up */
  279.     int        k_idleshifts;    /* Shifts that keep across idle */
  280.     int        k_idlebuckys;    /* Bucky bits that keep across idle */
  281. };
  282.  
  283.  
  284. /*
  285.  * The "special" entries' top 4 bits are defined below.  Generally they are
  286.  * used with a 4-bit parameter (such as a bit number) in the low 4 bits.
  287.  * The bytes whose top 4 bits are 0x0 thru 0x7 happen to be ascii
  288.  * characters.  They are not special cased, but just normal cased.
  289.  */
  290.  
  291. #define    SHIFTKEYS    0x80    /* thru 0x8F.  This key helps to determine the
  292.                    translation table used.  The bit
  293.                    position of its bit in "shiftmask"
  294.                    is added to the entry, eg
  295.                    SHIFTKEYS+LEFTCTRL.  When this entry is
  296.                    invoked, the bit in "shiftmask" is
  297.                    toggled.  Depending which tables you put
  298.                    it in, this works well for hold-down
  299.                    keys or press-on, press-off keys.  */
  300. #define    BUCKYBITS    0x90    /* thru 0x9F.  This key determines the state of
  301.                    one of the "bucky" bits above the
  302.                    returned ASCII character.  This is
  303.                    basically a way to pass mode-key-up/down
  304.                    information back to the caller with each
  305.                    "real" key depressed.  The concept, and
  306.                    name "bucky" (derivation unknown) comes
  307.                    from the MIT/SAIL "TV" system...they had
  308.                    TOP, META, CTRL, and a few other bucky
  309.                    bits.  The bit position of its bit in
  310.                    "buckybits", minus 7, is added to the
  311.                    entry; eg bit 0x00000400 is BUCKYBITS+3.
  312.                    The "-7" prevents us from messing up the
  313.                    ASCII char, and gives us 16 useful bucky
  314.                    bits.  When this entry is invoked,
  315.                    the designated bit in "buckybits" is
  316.                    toggled.  Depending which tables you put
  317.                    it in, this works well for hold-down
  318.                    keys or press-on, press-off keys.  */
  319. #define    FUNNY        0xA0    /* thru 0xAF.  This key does one of 16 funny
  320.                    things based on the low 4 bits: */
  321. #define    NOP        0xA0    /* This key does nothing. */
  322. #define    OOPS        0xA1    /* This key exists but is undefined. */
  323. #define    HOLE        0xA2    /* This key does not exist on the keyboard.
  324.                    Its position code should never be
  325.                    generated.  This indicates a software/
  326.                    hardware mismatch, or bugs. */
  327. #define    NOSCROLL    0xA3    /* This key alternately sends ^S or ^Q */
  328. #define    CTRLS        0xA4    /* This sends ^S and lets NOSCROLL know */
  329. #define    CTRLQ        0xA5    /* This sends ^Q and lets NOSCROLL know */
  330. #define    RESET        0xA6    /* Kbd was just reset */
  331. #define    ERROR        0xA7    /* Kbd just detected an internal error */
  332. #define    IDLE        0xA8    /* Kbd is idle (no keys down) */
  333. /* Combinations 0xA9 to 0xAF are reserved for non-parameterized functions */
  334.  
  335. #define    STRING        0xB0    /* thru 0xBF.  The low-order 4 bits index
  336.                    a table referenced via gp->KStrTab and
  337.                    select a string to be returned, char
  338.                    by char.  Each entry in KStrTab is a
  339.                    pointer to a character vector.  The vector
  340.                    contains a 1-byte length, followed by
  341.                    data. */
  342. /* Definitions for the individual string numbers: */
  343. #define    HOMEARROW    0x00
  344. #define    UPARROW        0x01
  345. #define    DOWNARROW    0x02
  346. #define    LEFTARROW    0x03
  347. #define    RIGHTARROW    0x04
  348. #define    PF1        0x05
  349. #define    PF2        0x06
  350. #define    PF3        0x07
  351. #define    PF4        0x08
  352. /* Note, these might be better served by their own non-FUNNY code with the
  353.    low 4 bits selecting which PF key.... */
  354. /* string numbers 9 thru F are reserved.  Users making custom entries, take
  355.    them from F downward to postpone confusion. */
  356.  
  357. /* combinations 0xC0 - 0xFF are reserved for more argument-taking entries */
  358.  
  359. #endif /* IDLEKEY */
  360. @
  361.  
  362.  
  363. 1.1
  364. log
  365. @Initial revision
  366. @
  367. text
  368. @d17 1
  369. a17 1
  370.  * routine, which executes every 2 ms or so.  
  371. d49 1
  372. a49 1
  373.  *    ERRORKEY    upon power-up, when errors are detected, 
  374. d78 1
  375. a78 1
  376. #ifndef KEYBS2   
  377. d90 1
  378. a90 1
  379. #endif KEYBS2
  380. d97 1
  381. a97 1
  382. #endif KEYBS2
  383. d103 1
  384. a103 1
  385. #endif KEYBKL
  386. d113 2
  387. a114 2
  388. #endif KEYBVT
  389. #endif sun2
  390. d202 1
  391. a202 1
  392.  * which is the mask which is actually used to determine the 
  393. d259 1
  394. a259 1
  395.  * The bytes whose top 4 bits are 0x0 thru 0x7 happen to be ascii 
  396. d331 1
  397. a331 1
  398. #endif IDLEKEY
  399. @
  400.